// pages/index/index.js
var WxParse = require('../../wxParse/wxParse.js');
var app = getApp;
const router = require('../../config').router

Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: {
      // content:"",
      // copyfrom:"",
      // createDateStr:"2018-04-17 13:38:54",
      // description:"华东地区最大的牡丹观赏园区——江宁谷里金陵国花园于近期开园。2000亩、数十种牡丹汇聚成一片惊艳花海，演绎出春色洋溢的交响曲，迎接八方宾客。",
      // id:1074,
      // image:"http://www.jsxcpd.com/ftpdata/userfile/survey/imges/20180417/20180417133739463.png",
      // isCollection:false,
      // thumbnail:"http://www.jsxcpd.com/ftpdata/userfile/survey/imges/20180417/20180417133849240.png",
      // title:"金陵国花园打造华东地区最大的牡丹观赏园区",
      // video:"http://www.jsxcpd.com/ftpdata/userfile/survery/video/20180417/20180417133848582.mp4"
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    /**
     * html解析示例
     */
    var that = this;
    var id = options.id;
    var article = '';
    //获取富文本文章
    wx.request({
      url: router,
      data: {
        appKey: 'w4q897jgvxkb',
        method: 'query.article.info',
        v: '1.0',
        format: 'json',
        id: id
      },
      success: function (res) {
        if (res.statusCode == 200 && res.data.error != 'error') {
          // console.log(res.data)
          that.setData({
            list: res.data
          })
          var star = res.data.content.indexOf('<p');
          var end = res.data.content.lastIndexOf('</p>')
          var article = res.data.content.substring(star, end + 4);
          article = res.data.content.substring(star, end + 4);
          // console.log(article)
          /**
          * WxParse.wxParse(bindName , type, data, target,imagePadding)
          * 1.bindName绑定的数据名(必填)
          * 2.type可以为html或者md(必填)
          * 3.data为传入的具体数据(必填)
          * 4.target为Page对象,一般为this(必填)
          * 5.imagePadding为当图片自适应是左右的单一padding(默认为0,可选)
          */
        // wx.showLoading({
        //   title: '加载中',
        // })
        // setTimeout(function(){
          WxParse.wxParse('article', 'html', article, that, 5);
          // wx.hideLoading()
        // },500)
        }
      }
    });
  },
  
  /**
   * banner视频点击
   */
  bannerClick: function (e) {
    var url = e.currentTarget.dataset.url;
    var id = parseInt(new Date().getTime() / 1000);
    wx.setStorageSync(id.toString(), url);
    if (url) {
      wx.navigateTo({
        url: '/pages/home/link/link?id=' + id
      })
    }
  }
})